﻿Public Module EuchreGlobals
#Region " Constants "
    Public Const MAX_TRICKS As Integer = 5
    Public Const DECK_AMOUNT As Integer = 24
#End Region

#Region " Enums "

    Public Enum Team
        One
        Two
    End Enum

    Public Enum Suite
        Spades = 1
        Clubs
        Diamonds
        Hearts
    End Enum

    Public Enum CardValue
        Nine = 1
        Ten
        Jack
        Queen
        King
        Ace
    End Enum

    Public Enum Name
        Kyle
        Megan
        Antigone
        Bailey
    End Enum

    Public Enum Position
        First = 1
        Second
        Third
        Fourth
    End Enum

#End Region

#Region " Card Functions "

    ''' <summary>
    ''' Creates a Euchre deck with random order
    ''' </summary>
    ''' <returns></returns>
    ''' A list of 24 cards used in a game of euchre in random order
    ''' <remarks></remarks>
    Public Function GetRandomDeck() As List(Of Card)
        Dim deck As New List(Of Card)
        Dim card As Card = Nothing
        Dim suite As Integer = 1
        For i As Integer = 0 To DECK_AMOUNT - 1
            card = New Card((i Mod 5) + 1, suite)
            deck.Add(card)
            If i Mod 4 = 3 Then suite += 1
        Next
        deck = RandomizeDeck(deck)
        Return deck
    End Function

    ''' <summary>
    ''' Takes a non-random deck and randomizes the order
    ''' </summary>
    ''' <param name="deck">A non-random deck of cards</param>
    ''' <returns>Random permutation of input deck</returns>
    ''' <remarks></remarks>
    Public Function RandomizeDeck(ByVal deck As List(Of Card)) As List(Of Card)
        Dim randomizedDeck As New List(Of Card)
        Dim min As Integer = 0
        Dim max As Integer = 0
        Dim position As Integer = 0
        Dim card As Card = Nothing
        'Assign shuffled values to deck
        While deck.Count > 0
            min = 1
            max = deck.Count
            position = GetRandom(min, max)
            card = deck.Item(position)
            randomizedDeck.Add(card)
            deck.RemoveAt(position)
        End While
        Return randomizedDeck
    End Function

    ''' <summary>
    ''' Random number generator
    ''' </summary>
    ''' <param name="Min">Minimum number to seed</param>
    ''' <param name="Max">Maximum number to seed</param>
    ''' <returns>A random number between min and max inclusive</returns>
    ''' <remarks></remarks>
    Public Function GetRandom(ByVal Min As Integer, ByVal Max As Integer) As Integer
        ' by making Generator static, we preserve the same instance '
        ' (i.e., do not create new instances with the same seed over and over) '
        ' between calls '
        Static Generator As System.Random = New System.Random()
        Return Generator.Next(Min, Max)
    End Function

    'TODO
    ''' <summary>
    ''' Chooses the optimal card to play in a given hand when leading
    ''' </summary>
    ''' <param name="trump">Trump declared this round</param>
    ''' <param name="hand">Cards available to choose from</param>
    ''' <param name="tricksPlayed">All tricks already played out</param>
    ''' <returns>optimal card to play</returns>
    ''' <remarks></remarks>
    Public Function PlayOptimalCardLead(ByVal trump As Suite, ByVal hand As Hand, ByVal tricksPlayed As List(Of Trick)) As Card
        Dim optimalCard As New Card(CardValue.Nine, Suite.Diamonds)
        Return (optimalCard)
    End Function

    'TODO
    ''' <summary>
    ''' Chooses the optimal card to play in a given hand when not leading
    ''' </summary>
    ''' <param name="trump">Trump declared this round</param>
    ''' <param name="hand">Cards available to choose from</param>
    ''' <param name="tricksPlayed">All tricks already played out</param>
    ''' <returns>optimal card to play</returns>
    ''' <remarks></remarks>
    Public Function PlayOptimalCardFollow(ByVal trump As Suite, ByVal hand As Hand, ByVal tricksPlayed As List(Of Trick), ByVal playsThisTrick As List(Of Play)) As Card
        Dim optimalCard As New Card(CardValue.Nine, Suite.Diamonds)
        Return (optimalCard)
    End Function

#End Region

#Region " Static Variables "

    Public EndServerConnectListener As Boolean = False

#End Region

End Module
